<template>
  <div class="tab">
    <ul>
      <li v-for="(item, key) in tabs"
          :key="item"
          :class="key === index ? 'active' : ''"
          @click="handleClick(key)">{{item}}</li>
    </ul>
  </div>
</template>

<script>
export default {
  name: 'Tab',
  props: {
    tabs: {
      type: Array
    }
  },
  data () {
    return {
      index: 0
    }
  },
  methods: {
    handleClick (index) {
      if (this.index !== index) {
        this.index = index
        this.$emit('tabClick', index)
      }
    }
  }
}
</script>

<style scoped>
  ul {
    display: flex;
    background-color: azure;
    width: 100%;
    justify-content: space-between;
    margin: 0 auto;
    padding: 0;
  }
  li {
    list-style: none;
    line-height: 56px;
    padding: 0 10px;
    cursor: pointer;
    flex: 1;
    text-align: center;
    font-size: 15px;
  }
  li:hover {
    background-color: #d4e9e9;
  }
  li.active {
    background-color: #0095ff;
    color: white;
  }
</style>
